# 2023/7/23 17:40
# xiashuobad
# logger
# PyCharm
"""
 * _ooOoo_
 * o8888888o
 * 88" . "88
 * (| -_- |)
 *  O\ = /O
 * ___/`---'\____
 * .   ' \\| |// `.
 * / \\||| : |||// \
 * / _||||| -:- |||||- \
 * | | \\\ - /// | |
 * | \_| ''\---/'' | |
 * \ .-\__ `-` ___/-. /
 * ___`. .' /--.--\ `. . __
 * ."" '< `.___\_<|>_/___.' >'"".
 * | | : `- \`.;`\ _ /`;.`/ - ` : | |
 * \ \ `-. \_ __\ /__ _/ .-` / /
 * ======`-.____`-.___\_____/___.-`____.-'======
 * `=---=' bug泛滥 佛已瘫痪
"""
from datetime import datetime
from mmcv import get_logger as get_logger_mmcv

from file_utils import MyPath


def get_logger(root_logdir, log_name):
    """
    创建日志对象
    :param root_logdir: 日志输出根目录
    :param log_name: 日志文件名
    :return:
    """
    # logger = logging.getLogger(log_name)
    # if logger.handlers:
    #     return logger
    log_dir = MyPath(root_logdir, f'{log_name}')
    MyPath(log_dir).makedirs()
    log_filename = f'{datetime.now().strftime("%Y-%m-%d-%H-%M-%S")}.log'
    # fh = logging.FileHandler(MyPath(log_dir, log_filename), mode='w', encoding='utf-8')
    # ch = logging.StreamHandler()
    # logger.addHandler(fh)
    # logger.addHandler(ch)
    # _format = logging.Formatter('%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s')
    # fh.setFormatter(_format)
    # logger.setLevel(logging.INFO)
    logger = get_logger_mmcv(log_name, log_dir.joinpath(log_filename).path)
    return logger
